package com.xuecheng.content.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.content.model.dto.QueryTeachplanMediaDto;
import com.xuecheng.content.model.po.TeachplanMedia;
import com.xuecheng.content.service.TeachplanMediaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("课程计划媒资关联controller")
@RestController
@RequestMapping("/teachplanMedia")
public class TeachplanMediaController {
    @Autowired
    TeachplanMediaService teachplanMediaService;

    @ApiOperation("根据条件查询课程计划媒资关联信息")
    @PostMapping
    public TeachplanMedia getTeachplanMedia(@RequestBody QueryTeachplanMediaDto dto) {
        if(dto == null) return null;
        return teachplanMediaService.getOne(new LambdaQueryWrapper<TeachplanMedia>()
                .eq(dto.getId() != null, TeachplanMedia::getId, dto.getId())
                .eq(dto.getMediaId() != null, TeachplanMedia::getMediaId, dto.getMediaId())
                .eq(dto.getTeachplanId() != null, TeachplanMedia::getTeachplanId, dto.getTeachplanId())
                .eq(dto.getCourseId() != null, TeachplanMedia::getCourseId, dto.getCourseId())
                .like(StringUtils.isNotBlank(dto.getMediaFileName()),TeachplanMedia::getMediaFilename,dto.getMediaFileName()));
    }
}
